<?php
/**
 * 版本:酷享云支付3.0版
 * 作者：余生
 * 官网：www.kuxiangcms.com
 * 技术QQ：2316803263
 * 酷享云支付官网:pay.kuxiangcms.cn
**/
//结算操作
include("../includes/common.php");
include './head.php';
if($islogin==1){}else exit("<script language='javascript'>window.location.href='./login.php';</script>");
?>
  <div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a>
                    <cite>结算列表操作</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
            </a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">

<?php
if(isset($_GET['batch'])){
	$batch=$_GET['batch'];
	$allmoney=$_GET['allmoney'];
	$count=$DB->query("SELECT * from pay_settle where batch='$batch'")->rowCount();
	$srow=$DB->query("SELECT * FROM pay_batch WHERE batch='{$batch}' limit 1")->fetch();
	if($srow['status']==0 && $srow['transfer_status']==0){
		$rs=$DB->query("SELECT * from pay_settle where batch='$batch'");
		while($row = $rs->fetch())
		{
			$dcmoney=$row['money']+$row['fee'];
			$DB->exec("update `pay_user` set `money`=`money`-'{$dcmoney}',`apply`='0' where `id`='{$row['pid']}'");
			$DB->exec("update `pay_settle` set `status`='1' where `id`='{$row['id']}'");
		}
		$DB->exec("update `pay_batch` set `status`='1' where `batch`='{$batch}'");
	}
?>          <div class="layui-card-body ">
          <table class="layui-table layui-form">
         <form action="download.php" lass="layui-form" method="get" role="form">
         <input type="hidden" name="batch" value="<?php echo $batch?>"/>
		 <input type="hidden" name="allmoney" value="<?php echo $allmoney?>"/>
          <thead>
          <tr>                             
         <th>结算记录数</th>
         <th>批次号</th>
         <th>总金额</th>
         <th>操作</th> 
         </tr>
         </thead>
         <tbody>
         <tr>
        <th>当前需要结算的共有<?php echo $count?>条记录</th>
        <th>批次号：<?php echo $batch?></th>
        <th>总金额：<?php echo $allmoney?>元</th>
        <th>
         <input type="submit" style='margin-top:1px' value="下载CSV文件" class="layui-btn layui-btn-normal layui-btn-xs"/>
        
         </form> 
         <form action="transfer.php" method="get" role="form">
    <input type="hidden" name="batch" value="<?php echo $batch?>"/>
            <p><input type="submit" style='margin-top:1px' value="单笔转账到支付宝账户" class="layui-btn layui-btn-normal layui-btn-xs"/></p>
       </form>
         <form action="wxtransfer.php" method="get" role="form">
      <input type="hidden" name="batch" value="<?php echo $batch?>"/>
            <p><input type="submit" style='margin-top:1px' value="微信企业付款" class="layui-btn layui-btn-normal layui-btn-xs"/></p>
          </form>
        </th>

      
         </tr>

         </tbody>    
      </table>

<?php }else{?>
		  <div class="layui-card-body ">
          <table class="layui-table layui-form">
          <thead>
          <tr>
                                        
         <th>批次号</th>
         <th>总金额</th>
         <th>生成时间</th>
         <th>状态</th>
         <th>操作</th> 
         </tr>
         </thead>
         <tbody>

<?php
$rs=$DB->query("SELECT * FROM pay_batch WHERE 1 order by time desc limit 10");
while($res = $rs->fetch())
{
echo '<tr><td><b>'.$res['batch'].'</b></td><td>'.$res['allmoney'].'</td><td>'.$res['time'].'</td><td>'.($res['status']==1?'<font color=green>已完成</font>':'<font color=red>未完成</font>').'</td><td><a href="./settle.php?batch='.$res['batch'].'&allmoney='.$res['allmoney'].'" class="btn btn-xs btn-info" onclick="return confirm(\'是否确定生成本批次结算列表？\');">生成结算列表</a></td></tr>';
}
?>
		  </tbody>
        </table>
<?php }?>
        </div>

         <div class="layui-form-item">
              <label class="layui-form-label">提示信息：</label>
              <div class="layui-form-mid layui-word-aux">*结算标准：金额大于<?php echo $conf['settle_money']?>元，或主动申请的（需扣除手续费<?php echo $conf['settle_fee']?>元） 结算列表请勿重复生成，CSV文件可以重复下载！</div>
            </div>
      </div>
    </div>
  </div>
  <style>
.pagination a,.pagination li {
        display:inline-block;
        padding:4px 7px;
        margin:0 2px;
        border:1px solid #D5D4D4;
        -webkit-border-radius:1px;
        -moz-border-radius:1px;
        border-radius:1px;
    }
    .pagination a,.pagination li {
        display:inline-block;
        list-style: none;
        text-decoration:none; color:#3399ff;
    }
    
    .pagination a:hover{
        border-color:#3399ff;
    }
    .pagination span.current{
        background:#3399ff;
        color:#FFF;
        font-weight:700;
        border-color:#3399ff;
    }
    .pagination{
      text-align: center;
    }</style>